/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>

#include "sle_error_code.h"
#include "sle_announce_stub.h"
#include "sle_announce_callback_stub.h"

class SleAnnounceStubTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp() override;
    void TearDown() override;

};
void SleAnnounceStubTest::SetUp()
{
}

void SleAnnounceStubTest::TearDown()
{
}

void SleAnnounceStubTest::SetUpTestCase()
{
}

void SleAnnounceStubTest::TearDownTestCase()
{
}

namespace OHOS {
namespace NearLink {
namespace SleStandard {

class SleAnnounceStubMock : public SleAnnounceStub {
    public:
        SleErrorCode RegisterAnnounceCallback(const sptr<ISleAnnounceCallback> &callback){
            return SLE_NO_ERROR;
        }
        SleErrorCode UnregisterAnnounceCallback(const sptr<ISleAnnounceCallback> &callback){
            return SLE_NO_ERROR;
        }
        SleErrorCode CreateAnnounceId(uint8_t &announceId){
            announceId = 1;
            return SLE_NO_ERROR;
        }
        SleErrorCode RemoveAnnounceId(uint8_t announceId){

            return SLE_NO_ERROR;
        }
        SleErrorCode StartAnnounce(uint8_t announceId, AnnounceData &datas, AnnounceParam &params){
            return SLE_NO_ERROR;
        }
        SleErrorCode StopAnnounce(uint8_t announceId){
            return SLE_NO_ERROR;
        }
};

class SleAnnounceCallbackStubMock :public SleAnnounceCallbackStub{
    public:
        void OnAnnounceStateChange(uint8_t announceId, int32_t state, bool terminal){

        }
};



/******************************************************framework test********************************************************************* */
HWTEST_F(SleAnnounceStubTest, OnAnnounceStateChangeInner_001, testing::ext::TestSize.Level0)
{
    SleAnnounceCallbackStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleAnnounceCallbackStub::GetDescriptor());

    data.WriteUint8(1);
    data.WriteInt32(0);
    data.WriteBool(true);

    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_CALLBACK_ANNOUNCE_STATE_CHANGE, data, reply, option), NO_ERROR);
}


/******************************************************service test********************************************************************* */
HWTEST_F(SleAnnounceStubTest, RegisterAnnounceCallbackInner_001, testing::ext::TestSize.Level0)
{
    SleAnnounceStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleAnnounceStub::GetDescriptor());

    sptr<IRemoteObject> remoteObject = new SleAnnounceCallbackStubMock();
    data.WriteRemoteObject(remoteObject);

    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_REGISTER_ANNOUNCE_CALLBACK, data, reply, option), NO_ERROR);
}

HWTEST_F(SleAnnounceStubTest, UnregisterAnnounceCallbackInner_001, testing::ext::TestSize.Level0)
{
    SleAnnounceStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleAnnounceStub::GetDescriptor());

    sptr<IRemoteObject> remoteObject = new SleAnnounceCallbackStubMock();
    data.WriteRemoteObject(remoteObject);

    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_UNREGISTER_ANNOUNCE_CALLBACK, data, reply, option), NO_ERROR);
}


HWTEST_F(SleAnnounceStubTest, CreateAnnounceIdInner_001, testing::ext::TestSize.Level0)
{
    SleAnnounceStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleAnnounceStub::GetDescriptor());


    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_CREATE_ANNOUNCE_ID, data, reply, option), NO_ERROR);
}


HWTEST_F(SleAnnounceStubTest, RemoveAnnounceIdInner_001, testing::ext::TestSize.Level0)
{
    SleAnnounceStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleAnnounceStub::GetDescriptor());

    data.WriteUint8(1);
    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_REMOVE_ANNOUNCE_ID, data, reply, option), NO_ERROR);
}


HWTEST_F(SleAnnounceStubTest, StartAnnounceInner_001, testing::ext::TestSize.Level0)
{
    SleAnnounceStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleAnnounceStub::GetDescriptor());

    data.WriteUint8(1);
    AnnounceData anndata;
    AnnounceParam param;
    data.WriteParcelable(&anndata);
    data.WriteParcelable(&param);

    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_ANNOUNCE_ENABLE, data, reply, option), NO_ERROR);
}

HWTEST_F(SleAnnounceStubTest, StopAnnounceInner_001, testing::ext::TestSize.Level0)
{
    SleAnnounceStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleAnnounceStub::GetDescriptor());

    data.WriteUint8(0);
    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_ANNOUNCE_DISABLE, data, reply, option), NO_ERROR);
}

}}}